// 一个数组a，用 a 数组去构建 b数组，有 a[i]个i+1
// [2,3,1] =》 [1,1,2,2,2,3]  求b中所有连续子数组的和 答案过大对1000000007取余

function solution(n, a) {
  let b = []
  for (let i = 0; i < n; i++) {
    for (let j = 1; j <= a[i]; j++) {
      b.push(i + 1)
    }
  }

  console.log(b);
  let sum = 0;
  const MOD = 1000000007;

  for (let i = 0; i < b.length; i++) {
    for (let j = i; j < b.length; j++) {
      sum += b[j] - b[i]
    }
  }


  return sum;
}

function main() {
  // console.log(solution(2, [2, 1]) === 2);
  // console.log(solution(3, [1, 2, 1]) === 6);
  // console.log(solution(4, [2, 3, 1, 1]) === 26);

  console.log(solution(4, [2, 3, 1, 1]));

}

main();